package com.css.zfzx.data.common;

/**
 * @Description: data
 * @Author: lhl
 * @CreateDate: 2021/10/21 14:59
 */
public class ResolveGeometryUtil {
    public static double[] bytesToOnePoint(byte[] arr){
        return new double[]{bytes2Double(arr,9),bytes2Double(arr,17)};
    }
    private static double bytes2Double(byte[] arr,int start) {
        long value = 0;
        for (int i = 0; i < 8; i++) {
            value |= ((long) (arr[start+i] & 0xff)) << (8 * i);
        }
        return Double.longBitsToDouble(value);
    }

    public static double[] bytesToMultipoint(String wkt) {
        String wktPart = "";
        if (wkt.toLowerCase().contains("multipoint")) {
            if (wkt.contains("((")){
                wktPart = wkt.substring(wkt.indexOf("(") + 2, wkt.lastIndexOf(")")-1);
            }else {
                wktPart = wkt.substring(wkt.indexOf("(") + 1, wkt.lastIndexOf(")"));
            }
        }else if (wkt.toLowerCase().contains("point")){
            wktPart = wkt.substring(wkt.indexOf("(") + 1, wkt.lastIndexOf(")"));
        }
        String[] array = wktPart.split(" ");
        return new double[]{Double.parseDouble(array[0]), Double.parseDouble(array[1])};
    }
}
